two pointer method for middle element finding